package com.alvin.springboot.dao;

import com.alvin.springboot.mapper.UserMapper;
import com.alvin.springboot.model.User;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Alvin
 * @Project_name: SpringbootTest
 * @Type_name: ${TYPE_NAME}
 * @DATE: 2017/2/27
 */
@Service("userDAOImpl")
public class UserDAOImpl extends SqlSessionDaoSupport implements UserMapper{

    @Autowired
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory){
        super.setSqlSessionFactory(sqlSessionFactory);
    }
    @Override
    public void save(User user){
        this.getSqlSession().insert("com.alvin.springboot.mapper.UserMapper.save", user);
    }
    @Override
    public void update(User user){
        this.getSqlSession().update("com.alvin.springboot.mapper.UserMapper.update",user);
    }
    @Override
    public void delete(String username){
        this.getSqlSession().delete("com.alvin.springboot.mapper.UserMapper.delete",username);
    }
    @Override
    public User findById(String username) {
        return this.getSqlSession().selectOne("com.alvin.springboot.mapper.UserMapper.findById",username);
    }

    @Override
    public List<User> findAll() {
        return this.getSqlSession().selectList("com.alvin.springboot.mapper.UserMapper.findAll");
    }

}
